package seqlist.leetcode;

import java.util.Arrays;

public class leetcode26 {
    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
//        int a=removeDuplicates(nums);
        removeDuplicates2(nums);
//        System.out.println(a);
        System.out.println(Arrays.toString(nums));
    }

    public static void removeDuplicates1(int[] nums) {
        int j = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i - 1] != nums[i]) {
                nums[j] = nums[i - 1];
                j++;
            }
            if (i == nums.length - 1) {
                nums[j] = nums[i];
            }

        }

    }

    public static int removeDuplicates(int[] nums) {
        int j = 1;
        int ret = nums[0];
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != ret) {
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
                j++;
                ret = temp;
            }
        }
        return j;
    }

    public static int removeDuplicates2(int[] nums) {
        int fir = 1;
        int sec = 1;
        while (fir < nums.length) {
            if (nums[fir] != nums[fir -1]) {
                nums[sec] = nums[fir];
                sec++;
            }
            fir++;
        }
        return sec;
    }
}